<template>
  <el-card>
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select
          v-model="categoryStore.category1Id"
          :disabled="scene ? true : false"
          @change="changeCategory1"
        >
          <el-option
            v-for="item in categoryStore.category1List"
            :key="item.id"
            :value="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          v-model="categoryStore.category2Id"
          :disabled="scene ? true : false"
          @change="changeCategory2"
        >
          <el-option
            v-for="item in categoryStore.category2List"
            :key="item.id"
            :value="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          v-model="categoryStore.category3Id"
          :disabled="scene ? true : false"
          @change="changeCategory3"
        >
          <el-option
            v-for="item in categoryStore.category3List"
            :key="item.id"
            :value="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts" name="Category">
import { onMounted } from 'vue'
import useCategoryStore from '@/store/modules/category'

let categoryStore = useCategoryStore()

defineProps(['scene'])

onMounted(() => {
  getCategory1()
})

const getCategory1 = () => {
  categoryStore.getCategory1List()
}

const changeCategory1 = () => {
  categoryStore.getCategory2List()
  categoryStore.category2Id = ''
  categoryStore.category3Id = ''
}

const changeCategory2 = () => {
  categoryStore.getCategory3List()
  categoryStore.category3Id = ''
}

const changeCategory3 = () => {}
</script>

<style scoped lang="scss">
.el-select {
  --el-select-width: 220px;
}
</style>
